package com.yidu.drug.service.impl;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yidu.drug.common.Message;
import com.yidu.drug.common.Page;
import com.yidu.drug.dao.PurchaseOrderModelMapper;
import com.yidu.drug.dao.QtSumModelMapper;
import com.yidu.drug.dao.QualityTestingModelMapper;
import com.yidu.drug.dao.RepertoryModelMapper;
import com.yidu.drug.model.DrugManagerModel;
import com.yidu.drug.model.InventoryModel;
import com.yidu.drug.model.PurchaseOrderModel;
import com.yidu.drug.model.QtSumModel;
import com.yidu.drug.model.QualityTestingModel;
import com.yidu.drug.model.RepertoryModel;
import com.yidu.drug.service.QtSumModelService;

@Service
public class QtSumModelServicelmpl implements QtSumModelService{

	@Resource
	private QtSumModelMapper qtSumModelDao;
	
	//采购Dao
	@Resource
	private PurchaseOrderModelMapper poDao;
	
	Message msg = new Message();
	
	@Resource
	private RepertoryModelMapper repertoryModelDao;
	
	@Override
	public int deleteByPrimaryKey(String sumId) {
		// TODO Auto-generated method stub
		return qtSumModelDao.deleteByPrimaryKey(sumId);
	}

	@Override
	public int insert(QtSumModel record) {
		// TODO Auto-generated method stub
		return qtSumModelDao.insert(record);
	}

	@Override
	public int insertSelective(QtSumModel record) {
		// TODO Auto-generated method stub
		return qtSumModelDao.insertSelective(record);
	}

	@Override
	public QtSumModel selectByPrimaryKey(String sumId) {
		// TODO Auto-generated method stub
		return qtSumModelDao.selectByPrimaryKey(sumId);
	}

	@Override
	public int updateByPrimaryKeySelective(QtSumModel record,String poId) {
		// TODO Auto-generated method stub
		//定义一个rows得到质检总报表的修改方法
		int rows=qtSumModelDao.updateByPrimaryKeySelective(record);
		//if循环 如果rows大于0
		if(rows>0){
			//进行订单的状态修改
			//new出订单
			PurchaseOrderModel po = new PurchaseOrderModel();
			//给订单ID赋值
			po.setPoId(poId);
			//给订单状态赋值
			po.setPoState("已审核,已采购,已提交,已质检,未入库");
			//执行订单中的修改方法 
			poDao.updateByPrimaryKeySelective(po);
		}
		//返回 rows
		return rows;
	}

	@Override
	public int updateByPrimaryKey(QtSumModel record) {
		// TODO Auto-generated method stub
		return qtSumModelDao.updateByPrimaryKey(record);
	}

	@Override
	public Map<String, Object> findAll(QtSumModel record) {
		//分页
		Page page = new Page();
		//给分页赋值
		page.setPage(Integer.valueOf(record.getPage()));
		//给页面总数分页赋值
		page.setRows(Integer.valueOf(record.getLimit()));
		//把上面赋值的分页给质检总报表的分页赋值
		record.setPages(page);
		//map集合
		Map<String,Object> map =  new HashMap<String,Object>();
 		//if循环药品和模中的分页C做对比
		if("drug".equals(record.getCondition())){
			//code返回0
			map.put("code", 0);
			//msg返回空
			map.put("msg", "");
			//count返回质检总报表的药品分页方法
			map.put("count", qtSumModelDao.findDrugProductionRows(record));
			//data返回药品方法
			map.put("data", qtSumModelDao.findDrugProduction(record));
		//循环材料和模中的分页C做对比
		}else if("metails".equals(record.getCondition())){
			//code返回0
			map.put("code", 0);
			//msg返回空
			map.put("msg", "");
			//count返回质检总报表的药材分页方法
			map.put("count", qtSumModelDao.findMetailsPurchaseRows(record));
			//data返回质检总报表的药材方法
			map.put("data", qtSumModelDao.findMetailsPurchase(record));
		}
		//返回map
 		return map;
	}

	
	
}
